﻿using System;
using System.Collections.Generic;

using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using Task.Common.Entity;
using Task.Common.Interface;
using Common.Service;
using Common.BasePages;
using OC.Common.Entity;

namespace Task
{
    public partial class AddTrust : BasePage
    {
        private OC.Common.Entity.UserEntity _user;
        public OC.Common.Entity.UserEntity UserEntity 
        {
            get 
            {
                if (_user == null) 
                {
                    _user = UserInfo as OC.Common.Entity.UserEntity;
                }
                return _user;
            }
        }
        private IDelegation _IDelegation;
        public IDelegation IDelegation 
        {
            get 
            {
                if (_IDelegation == null) 
                {
                    _IDelegation = ServiceContainer.GetService<IDelegation>();
                }
                return _IDelegation;
            }
        }
        protected void Page_Load(object sender, EventArgs e)
        {
            
        }

        protected void btnSave_Click(object sender, EventArgs e)
        {
            //UserEntity list = Session["UserInfo"] as UserEntity;
            DelegationEntitiy entity = new DelegationEntitiy();
            entity.DELEGATION_ID = Guid.NewGuid().ToString();
            entity.CREATE_BY = UserEntity.USER_CODE;
            entity.CREATE_DATE = DateTime.Now;
            entity.DELEGATOR_STATUS = "0";
            entity.DELEGATOR_USER = hidUserId.Value;
            entity.EFFECT_FROM = Convert.ToDateTime(txtStartDate.Text);
            entity.EFFECT_TO = Convert.ToDateTime(txtEndDate.Text);
            entity.END_DATE = Convert.ToDateTime(txtEndDate.Text);
            entity.IS_ACTIVE = "1";
            entity.START_DATE = Convert.ToDateTime(txtStartDate.Text);
            entity.STEP_NAME = txtUser.Text;
            entity.TASK_USER = UserEntity.USER_CODE;
            entity.UPDATE_BY = UserEntity.USER_CODE;
            entity.UPDATE_DATE = DateTime.Now;
            entity.COMMENT = txtDesc.Value;
            entity.Summary = "";
            entity.PROCESS_NAME = "";
            
            IDelegation.InsertData(entity);
            Page.ClientScript.RegisterClientScriptBlock(GetType(), "insert", "<script>window.close();parent.location.reload();</script>");
        }
    }
}